package com.wangzhixuan.controller;

import com.wangzhixuan.constant.SystemConstant;
import com.wangzhixuan.db.bean.Customer;
import com.wangzhixuan.service.CustomerService;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class BaseController {

    @Autowired
    private CustomerService customerService;
    /**
     * Get current loginned user
     *
     * @param request
     * @return
     */
    protected Customer getCurrentCustomer(HttpServletRequest request) {
        Customer customer = (Customer) request.getSession().getAttribute(
                SystemConstant.SESSION_CUSTOMER_KEY);
        if(customer.getId()==0){
            customer=customerService.getCustomerByOpenId(customer.getOpenId());
            HttpSession session = request.getSession();
            customer.setPassword("");
            session.setAttribute(SystemConstant.SESSION_CUSTOMER_KEY, customer);
        }
        return customer;
    }

}
